package com.wiscamp.ninechapters.tags.infrastructure.mappers;

import com.wiscamp.ninechapters.tags.infrastructure.po.CourseView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Collection;


/**
 * 课程知识点仓储对象
 *
 * @author yifeng
 */
@Repository
public interface CourseViewMapper extends JpaRepository<CourseView, Long>, JpaSpecificationExecutor<CourseView> {
    /**
     * 通过代码获取课程
     *
     * @param courseCode
     * @return
     */
    @Query(value = "select e from CourseView e where e.courseCode = :courseCode")
    CourseView findByCourseCode(String courseCode);

    /**
     * 通过名称获取课程列表
     *
     * @param courseName
     * @return
     */
    @Query(value = "select e from CourseView e where e.courseName = :courseName")
    Collection<CourseView> findListByCourseName(String courseName);

    /**
     * 获取所有未删除课程
     *
     * @return
     */
    @Query(value = "select e from CourseView e where e.enabled")
    Collection<CourseView> findListByAvailable();

    /**
     * 分页获取课程列表
     *
     * @param spec
     * @param pageable
     * @return
     */
    Page<CourseView> findAll(Specification<CourseView> spec, Pageable pageable);
}